<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./echarts.common.min.js"></script>
    <script src="./jquery-1.12.4.min.js"></script>
</head>
<body>
     <!-- 为ECharts准备一个具备大小（宽高）的Dom -->
     <div id="main" style="width: 600px;height:400px;"></div>
     
    <script>
         // 基于准备好的dom，初始化echarts实例
         var myChart = echarts.init(document.getElementById('main'));
        // 指定图表的配置项和数据

        tempData = [];
        timeData = [];
        count = 1
        var option = {
            title: {
                text: 'ECharts 入门示例'
            },
            tooltip: {},
            legend: {
                data: ['温度']
            },
            xAxis: {
                data: []
            },
            yAxis: {},
            series: [{
                name: '温度',
                type: 'line',
                data: []
            }]
        };
        $(function(){
            setInterval(function(){
                //从GetTemp.do中获取温度信息
                $.ajax({
                    type:"GET",
                    url:'http://10.1.93.241:8082/GetTemp.do',
                    success:function(res){
                        //res 中包含着温度信息
                        var obj = JSON.parse(res)
                        var temp = obj["Temp"];
                        tempData.push(temp);
                        console.log(temp);
                        //时间
                        var now = new Date();
                        timeData.push(now.getMinutes() + ":" + now.getSeconds());

                        //对数组中的数据进行截取
                        //timeData.slice(timeData.length-20<0?0:timeData.length-20);
                        //tempData.slice(timeData.length-20<0?0:timeData.length-20);

                        option.series[0].data = tempData.slice(tempData.length-20<0?0:timeData.length-10);
                        //温度数据
                        option.xAxis.data = timeData.slice(timeData.length-20<0?0:timeData.length-10);;
                        //使用刚指定的配置项和数据显示图表。
                        myChart.setOption(option);
                    }
                });
            },1000)
        });    
    </script>
</body>
</html>